package com.example.mapper;

import com.example.pojo.Student;
import com.example.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    /**
     * 条件分页查询学员信息
     */
    List<Student> list(StudentQueryParam studentQueryParam);

    /**
     * 根据ID批量删除学员
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 新增学员
     */
    @Insert("insert into student(name,no,gender,phone,id_card,is_college,address,degree,graduation_date,clazz_id,create_time,update_time) " +
            "values(#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    /**
     * 根据ID查询学员信息
     */
    @Select("select s.id, s.name, s.no, s.gender, s.phone, s.id_card, s.is_college, s.address, s.degree, s.graduation_date, s.clazz_id, s.violation_count, s.violation_score, s.create_time, s.update_time, c.name clazzName " +
            "from student s left join clazz c on s.clazz_id = c.id where s.id=#{id}")
    Student getById(Integer id);

    /**
     * 修改学员信息
     */
    void update(Student student);

    /**
     * 学员学历统计
     */
    List<Map<String, Object>> countStudentDegreeData();

    /**
     * 班级人数统计
     */
    List<Map<String, Object>> countStudentCountData();

    /**
     * 根据班级ID查询学员
     */
    @Select("select id from student where clazz_id = #{clazzId}")
    List<Student> getByClazzId(Integer clazzId);
}
